<?php
namespace Api\Controller;
use Api\Controller\CommonController;
class VersionController extends CommonController {
	
	public function _initialize(){
		parent::_initialize();
	}
	
	/**
	 * 检测版本
	 */
	public function checkVersion(){
	    $data=array(
	        'device'=>I('post.device'),
	        'appID' =>I('post.appID')
	    );
	    if(!isNotEmptyArr($data)) $this->_returnJson(array("result"=>0,"info"=>"missing parameter","code"=>"123"));
	     
	    $version=D('version')->where(array('device'=>$data['device'],'isOn'=>1,'appID'=>$data['appID']))->find();
	    if(!$version || $version['status']!= 1 ){
	        $currentVersion['status']=0;
	    }
	    else{
	        $currentVersion['status']=1;
	    }
	
	    //查找最新版本
	    $checkNew=D('version')->where(array('device'=>$data['device'],'isOn'=>1,'status'=>1))->order('verID desc')->find();
	    if($version['verID']==$checkNew['verID']){
	        $newVersion['isNew']=0;
	    }
	    elseif($checkNew['verID']>$version['verID']){
	        $newVersion=array(
	            'isNew' => 1,
	            'url' =>$checkNew['url'],
	            'content' => $checkNew['content'],
	        );
	
	    }
	    else{
	        $newVersion['isNew']=0;
	    }
	
	    $this->_returnJson(array("result"=>1,"current"=>$currentVersion,"new"=>$newVersion,"serverList"=>C('SERVERLIST')));
	}
}